﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

public class Railgun : Weapon
{
    protected float m_Power = 120.0f;
    public override float ShutRange
    {
        get { 
            if(m_Ship)
            {
                return Mathf.Clamp(m_Ship.m_ShipStruct.m_ElectricPower / m_Power, 0, 1) * m_ShutRange * m_ShotRangeMultiply;
            }
            else
            {
                return m_ShutRange * m_ShotRangeMultiply;
            }
        }
    }

    public Railgun()
    {
        m_ShutRange = 15;
        Description = "射程远，威力大，穿透强，就是费电. 射程、伤害和消耗的电力都与舰船的最大电力输出功率呈正比";
    }

    public override FlyItem Fire(GameObject ship, WeaponSlot slot, Vector3 position, Vector3 direction)
    {
        Slot = slot;
        if(ship)
            m_Ship = ship.GetComponent<Ship>();
        if (!m_Ship)
            return null;

        float expand = Math.Min(m_Ship.m_ShipStruct.m_ElectricPower, m_Power * 0.3f);
        if (m_Ship.m_ShipStruct.Electric > expand)
        {
            m_Ship.m_ShipStruct.Electric -= expand;
            return base.Fire(ship, slot, position, direction);
        }
        return null;
    }
}